#ifndef TESTMAPEOFECHA_H
#define TESTMAPEOFECHA_H

#include "../common/CargadorMasivo.h"
#include "../common/mapeador.h"

void testMapeoFecha (){
    //si viene la franja horaria: 00:00 - 00:30 21/02/2012 ->
    //se obtendria la salida: 000101100010101010000000

    //si viene la franja horaria: 00:30 - 01:00 21/02/2012 ->
    //se obtendria la salida: 000101100010101010000010

    //si viene la franja horaria: 01:30 - 02:00 21/02/2012 ->
    //se obtendria la salida: 000101100010101010000110

    //si viene la franja horaria: 00:00 - 00:30 01/01/1990 ->
    //se obtendria la salida: 00000000 0001 00001 0000000

    unsigned int anio = 2012;
    unsigned char mes = 02;
    unsigned char dia = 21;
    unsigned char byte;
    std::string rango1 = "00:00 - 00:30";
    std::string rango2 = "00:30 - 01:00";
    std::string rango3 = "01:30 - 02:00";
    Mapeador* conversor = Mapeador::getInstance();

/******************** CONVIERTO PRIMER RANGO ************************************/
    u_int32_t idFechaConvertida = conversor->convertirRango(anio, mes , dia , rango1);
    unsigned char fechaConvertida[4];
    memset(fechaConvertida, '\0', 4);
    memcpy(fechaConvertida, &idFechaConvertida , sizeof (unsigned char) * 3);

    int count = 0;
    int i = 0;
   while ( i < 3){
        byte = (unsigned char)fechaConvertida[i];

    for (count = 7; count >= 0; count--){
        if (byte & ( 1 << count ) )
                std::cout << 1 << " ";
        else
                std::cout << 0 << " ";
    }
    i++;
   }
   std::cout << std::endl;

   anio = mes = dia = '\0';
   rango1.clear();
   conversor->recuperarRango(idFechaConvertida, &anio, &mes, & dia, &rango1);
   std::cout << "Recupero Clave: " << "anio: " << anio << " mes: " << (int)mes << " dia: " << (int)dia << " rango: " << rango1 << std::endl;

   /******************** CONVIERTO SEGUNDO RANGO ************************************/
   std::cout << std::endl;
   idFechaConvertida = conversor->convertirRango(anio, mes , dia , rango2);
   memset(fechaConvertida, '\0', 4);
   memcpy(fechaConvertida, &idFechaConvertida , sizeof (unsigned char) * 3);

       count = 0;
       i = 0;
      while ( i < 3){
        byte = (unsigned char)fechaConvertida[i];

       for (count = 7; count >= 0; count--){
        if (byte & ( 1 << count ) )
                std::cout << 1 << " ";
        else
                std::cout << 0 << " ";
       }
       i++;
      }
      std::cout << std::endl;

      anio = mes = dia = '\0';
      rango2.clear();
      conversor->recuperarRango(idFechaConvertida, &anio, &mes, & dia, &rango2);
      std::cout << "Recupero Clave: " << "anio: " << anio << " mes: " << (int)mes << " dia: " << (int)dia << " rango: " << rango2 << std::endl;

      /******************** CONVIERTO TERCER RANGO ************************************/
      std::cout << std::endl;
      idFechaConvertida = conversor->convertirRango(anio, mes , dia , rango3);
      memset(fechaConvertida, '\0', 4);
      memcpy(fechaConvertida, &idFechaConvertida , sizeof (unsigned char) * 3);

          count = 0;
          i = 0;
         while ( i < 3){
                byte = (unsigned char)fechaConvertida[i];

          for (count = 7; count >= 0; count--){
                if (byte & ( 1 << count ) )
                        std::cout << 1 << " ";
                else
                        std::cout << 0 << " ";
          }
          i++;
         }
         std::cout << std::endl;

         anio = mes = dia = '\0';
         rango3.clear();
         conversor->recuperarRango(idFechaConvertida, &anio, &mes, & dia, &rango3);
         std::cout << "Recupero Clave: " << "anio: " << anio << " mes: " << (int)mes << " dia: " << (int)dia << " rango: " << rango3 << std::endl;

         /******************** CONVIERTO CUARTO RANGO ************************************/
        anio = 1990;
        mes = 1;
        dia = 1;

        std::cout << std::endl;
        idFechaConvertida = conversor->convertirRango(anio, mes , dia , rango1);
        memset(fechaConvertida, '\0', 4);
        memcpy(fechaConvertida, &idFechaConvertida , sizeof (unsigned char) * 3);

        count = 0;
        i = 0;
       while ( i < 3){
            byte = (unsigned char)fechaConvertida[i];

        for (count = 7; count >= 0; count--){
            if (byte & ( 1 << count ) )
                    std::cout << 1 << " ";
            else
                    std::cout << 0 << " ";
        }
        i++;
       }
       std::cout << std::endl;

       anio = mes = dia = '\0';
       rango1.clear();
       conversor->recuperarRango(idFechaConvertida, &anio, &mes, & dia, &rango1);
       std::cout << "Recupero Clave: " << "anio: " << anio << " mes: " << (int)mes << " dia: " << (int)dia << " rango: " << rango1 << std::endl;

       std::cout << std::endl;

}

#endif // TESTMAPEOFECHA_H
